﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// 文件名：ClsPeportDAL.cs
/// 作  者：黄纲
/// 时  间：2007.02.02
/// 说  明：ClsPeportDAL类用于报表管理信息相关处理
/// </summary>
public class ClsReportDAL
{
    /// <summary>
    /// 数据库连接字符串
    /// </summary>
    private static string strSqlConnectionString = ConfigurationManager.AppSettings["SQLCONNECTIONSTRING"];

    public DataSet GetReportInfo()
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetReportInfo", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    public Boolean AddReportInfo(string Name, string Url, int Is_Stop, string Remark)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_AddReportInfo", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@name", SqlDbType.NVarChar, 255);
        com.Parameters["@name"].Value = Name;
        com.Parameters.Add("@url", SqlDbType.NVarChar, 255);
        com.Parameters["@url"].Value = Url;
        com.Parameters.Add("@is_stop", SqlDbType.Int, 4);
        com.Parameters["@is_stop"].Value = Is_Stop;
        com.Parameters.Add("@remark", SqlDbType.NVarChar, 255);
        com.Parameters["@remark"].Value = Remark;
        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    public Boolean UpdateReportInfo(int ID, string Name, string Url, int Is_Stop, string Remark)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_UpdateReportInfo", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@id", SqlDbType.Int, 4);
        com.Parameters["@id"].Value = ID;
        com.Parameters.Add("@name", SqlDbType.NVarChar, 255);
        com.Parameters["@name"].Value = Name;
        com.Parameters.Add("@url", SqlDbType.NVarChar, 255);
        com.Parameters["@url"].Value = Url;
        com.Parameters.Add("@is_stop", SqlDbType.Int, 4);
        com.Parameters["@is_stop"].Value = Is_Stop;
        com.Parameters.Add("@remark", SqlDbType.NVarChar, 255);
        com.Parameters["@remark"].Value = Remark;
        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    public Boolean DeleteReportInfo(int ID, int Type)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_DeleteReportInfo", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@id", SqlDbType.Int, 4);
        com.Parameters["@id"].Value = ID;
        com.Parameters.Add("@type", SqlDbType.Int, 4);
        com.Parameters["@type"].Value = Type;

        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }

    public DataSet GetReportSetInfo()
    {
        DataSet dst = new DataSet();
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlDataAdapter dat = new SqlDataAdapter("Pro_GetReportSetInfo", con);

        dat.SelectCommand.CommandType = CommandType.StoredProcedure;

        try
        {
            dat.Fill(dst);
        }
        catch
        {
            dst = null;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }

        return dst;
    }

    public Boolean UpdateReportSetInfo(string Path, int Width, int Height)
    {
        SqlConnection con = new SqlConnection(strSqlConnectionString);
        SqlCommand com = new SqlCommand("Pro_UpdateReportSetInfo", con);

        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@path", SqlDbType.NVarChar, 255);
        com.Parameters["@path"].Value = Path;
        com.Parameters.Add("@width", SqlDbType.Int, 4);
        com.Parameters["@width"].Value = Width;
        com.Parameters.Add("@height", SqlDbType.Int, 4);
        com.Parameters["@height"].Value = Height;
        try
        {
            con.Open();
            com.ExecuteNonQuery();

            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }
   
}
